﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Sys.WebRes.Data;
using System.Configuration;

namespace WebResource
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public MvcApplication()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="routes"></param>
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "File", // 路由名称
                "File/{type}/{folder}/{fileName}/{small}", // 带有参数的 URL
                new { controller = "File", action = "Index", 
                    type = UrlParameter.Optional, 
                    folder = UrlParameter.Optional, 
                    fileName = UrlParameter.Optional,
                    small = UrlParameter.Optional
                },  // 参数默认值
                new String[] { "Sys.WebRes.Publish.Controllers" }
            );

            routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new {controller = "Home", action = "Index", id = UrlParameter.Optional},  // 参数默认值
                new String[] { "Sys.WebRes.Publish.Controllers"}
            );
        }

        protected void Application_Start()
        {
            //ConfigurationManager.ConnectionStrings["ResourceSysEntities"].ConnectionString
            //    = string.Format(ConfigurationManager.ConnectionStrings["ResourceSysEntities"].ConnectionString,
            //                    this.Server.MapPath("bin"));

            //Console.Write(this.Server.MapPath("/"));

            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            using (var db = new ResourceSysEntities())
            {
                db.InitializeMaster();
            }
        }
    }
}